<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js" type="text/javascript"></script>
  <style>

  </style>
</head>

<body>
  <div id='root'>
    <!-- key大概率是数据库的ID -->
    <!-- 如果没有设置，默认使用数组下标 -->
    <div v-for='(item,index) in list' :key='item.key'>
      {{ item.num }} <input />
    </div>

    <button @click='remove'>remove</button>
  </div>

  <!-- 0 1 2 3 4  -->
  <!-- 0 1 2 3 -->

  <!-- a b c d -->
  <!-- a c d -->
  <script>
    // * 就地复用
    // * 
    let vm = new Vue({
      el: '#root',
      data: function () {
        return {
          list: [{
              num: 1,
              key: Math.random()
            },
            {
              num: 2,
              key: Math.random()
            },
            {
              num: 3,
              key: Math.random()
            },
            {
              num: 4,
              key: Math.random()
            },
            {
              num: 5,
              key: Math.random()
            },
          ]
        }
      },
      methods: {
        remove() {
          this.list.splice(2, 1);
        }
      },
      computed: {

      }
    })

  </script>
</body>

</html>
